package com.j2eefast.flowable.bpm.service;


import cn.hutool.core.util.IdUtil;
import com.j2eefast.flowable.bpm.entity.bpmCrmLoanEntity;
import com.j2eefast.flowable.bpm.mapper.bpmCrmLoanMapper;
import com.j2eefast.common.core.mutidatasource.annotaion.DataSource;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;
import java.util.Arrays;
/**
 *
 * 贷款信息表Service接口
 * @author: yhli
 * @date 2020-06-27 14:43
 */
@Service
public class bpmCrmLoanService extends ServiceImpl<bpmCrmLoanMapper,bpmCrmLoanEntity> {

	@Resource
	private bpmCrmLoanMapper bpmCrmLoanMapper;

	/**
	 * mybaitis-plus 页面分页查询
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<bpmCrmLoanEntity> queryWrapper = new QueryWrapper<bpmCrmLoanEntity>();
              String saleCode = (String) params.get("saleCode");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleCode), "sale_code", saleCode);
                               String saleUserid = (String) params.get("saleUserid");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleUserid), "sale_userid", saleUserid);
          String saleOrderNumber = (String) params.get("saleOrderNumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleOrderNumber), "sale_order_number", saleOrderNumber);
          String outCarVin = (String) params.get("outCarVin");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVin), "out_car_vin", outCarVin);
          String outCarVehicle = (String) params.get("outCarVehicle");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVehicle), "out_car_vehicle", outCarVehicle);
          String loanApplyMoney = (String) params.get("loanApplyMoney");
         queryWrapper.eq(ToolUtil.isNotEmpty(loanApplyMoney), "loan_apply_money", loanApplyMoney);
          String loanApplyMemo = (String) params.get("loanApplyMemo");
         queryWrapper.eq(ToolUtil.isNotEmpty(loanApplyMemo), "loan_apply_memo", loanApplyMemo);
          String loanSpecialistReview = (String) params.get("loanSpecialistReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(loanSpecialistReview), "loan_specialist_review", loanSpecialistReview);
          String loanContractFilepath = (String) params.get("loanContractFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(loanContractFilepath), "loan_contract_filepath", loanContractFilepath);
          String loanMoney = (String) params.get("loanMoney");
         queryWrapper.eq(ToolUtil.isNotEmpty(loanMoney), "loan_money", loanMoney);
          String loanTitleSpecialistProcess = (String) params.get("loanTitleSpecialistProcess");
         queryWrapper.eq(ToolUtil.isNotEmpty(loanTitleSpecialistProcess), "loan_title_specialist_process", loanTitleSpecialistProcess);
          String loanFilepath = (String) params.get("loanFilepath");
         queryWrapper.eq(ToolUtil.isNotEmpty(loanFilepath), "loan_filepath", loanFilepath);
          String checkmoneyCashierReview = (String) params.get("checkmoneyCashierReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(checkmoneyCashierReview), "checkmoney_cashier_review", checkmoneyCashierReview);
          String checkmoneyProofpath = (String) params.get("checkmoneyProofpath");
         queryWrapper.eq(ToolUtil.isNotEmpty(checkmoneyProofpath), "checkmoney_proofpath", checkmoneyProofpath);
          String checkmoneyLoanamountreceived = (String) params.get("checkmoneyLoanamountreceived");
         queryWrapper.eq(ToolUtil.isNotEmpty(checkmoneyLoanamountreceived), "checkmoney_loanamountreceived", checkmoneyLoanamountreceived);
          String checkmoneyReceiptnumber = (String) params.get("checkmoneyReceiptnumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(checkmoneyReceiptnumber), "checkmoney_receiptnumber", checkmoneyReceiptnumber);
          String checkmoneyMemo = (String) params.get("checkmoneyMemo");
         queryWrapper.eq(ToolUtil.isNotEmpty(checkmoneyMemo), "checkmoney_memo", checkmoneyMemo);
          String orderTakeEffectTime = (String) params.get("orderTakeEffectTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(orderTakeEffectTime), "order_take_effect_time", orderTakeEffectTime);
          String collectionTime = (String) params.get("collectionTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(collectionTime), "collection_time", collectionTime);
             String interestRate = (String) params.get("interestRate");
         queryWrapper.eq(ToolUtil.isNotEmpty(interestRate), "interest_rate", interestRate);
          String costOfCapital = (String) params.get("costOfCapital");
         queryWrapper.eq(ToolUtil.isNotEmpty(costOfCapital), "cost_of_capital", costOfCapital);
          String financeManagerReview = (String) params.get("financeManagerReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(financeManagerReview), "finance_manager_review", financeManagerReview);
          String managerReview = (String) params.get("managerReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(managerReview), "manager_review", managerReview);
  		Page<bpmCrmLoanEntity> page = bpmCrmLoanMapper.selectPage(new Query<bpmCrmLoanEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

    /**
     * 自定义分页查询，含关联实体对像
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params,bpmCrmLoanEntity bpmCrmLoanEntity) {
		Page<bpmCrmLoanEntity> page = bpmCrmLoanMapper.findPage(new Query<bpmCrmLoanEntity>(params).getPage(), bpmCrmLoanEntity,(String) params.get(Constant.SQL_FILTER))  ;
		return new PageUtil(page);
	}
	/**
     * 批量删除
     */
    @DataSource(name="FLOWABLE")
	@Transactional(rollbackFor = Exception.class)
	public boolean deletebpmCrmLoanByIds(String[] ids) {
		return removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
    @DataSource(name="FLOWABLE")
	public boolean deletebpmCrmLoanById(String id) {
		return removeById(id);
	}

	/**
     * 保存
     */
    @DataSource(name="FLOWABLE")
	public boolean savebpmCrmLoan(bpmCrmLoanEntity bpmCrmLoan){
        bpmCrmLoan.setId(IdUtil.fastSimpleUUID());
        return save(bpmCrmLoan);
    }

	/**
     * 修改根居ID
     */
    @DataSource(name="FLOWABLE")
	public boolean updatebpmCrmLoanById(bpmCrmLoanEntity bpmCrmLoan) {
		return updateById(bpmCrmLoan);
	}

	/**
     * 根居ID获取对象
     */
    @DataSource(name="FLOWABLE")
	public bpmCrmLoanEntity getbpmCrmLoanById(String id){
		return getById(id);
	}
}
